package com.byl.sdk.utils;


import javax.security.auth.login.CredentialNotFoundException;
import java.util.Map;

public class MapUtils {

    /**
     * 获取map中对应key的值
     *
     * @param
     * @return 如果map或key为空  或者不包含key返回空字符串 否则返回该key的值
     **/

    public static String getValue(Map map, String key) {
        if (null == map || null == key)
            return "";
        // 判断map中是否含有key
        if (!map.containsKey(key))
            return "";
        Object obj = map.get(key);
        if (null == obj)
            return "";
            return obj.toString();
    }

    /**
     * 获取map中的double类型的值
     * @param map
     * @param key
     * @return
     */
    public static Double getDoubleValue(Map map,String key){
        if (null == map || null == key)
            return 0d;
        // 判断map中是否含有key
        if (!map.containsKey(key))
            return 0d;
        Object obj = map.get(key);
        if (null == obj)
            return 0d;
        return Double.parseDouble(obj.toString());
    }

    public static int getIntValue(Map map, String key) {
        if (null == map || null == key)
            return -1;
        // 判断map中是否含有key
        if (!map.containsKey(key))
            return -1;
        Object obj = map.get(key);
        if (null == obj)
            return -1;
        return Integer.parseInt(obj.toString());
    }
}